package com.lz.wsy.controller;

import com.lz.utils.Result;
import com.lz.wsy.pojo.Book;
import com.lz.wsy.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/book")
public class BookController {

    @Autowired
    private BookService bookService;

    /** 分页查询所有数据 */
    @GetMapping("/page")
    public Result page(@RequestParam(value = "pageNumber",defaultValue = "1") Integer pageNumber,
                       @RequestParam(value = "pageSize",defaultValue = "5") Integer pageSize,
                       Book book){
        return Result.success(bookService.pageVo(pageNumber,pageSize,book));
    }

    /** 通过主键查询单条电子样册 */
    @GetMapping("/get/{bookId}")
    public Result get(@PathVariable("bookId") Integer bookId){
        return Result.success(bookService.get(bookId));
    }

    /** 新增或者编辑电子样册 */
    @PostMapping("/saveAndEdit")
    public Result saveAndEdit(@RequestBody Book book){
        return Result.success(bookService.addAndEdit(book));
    }


    /** 删除单条数据 */
    @GetMapping("/remove")
    public Result delete(@RequestParam("bookId") Integer bookId){
        return Result.success(bookService.delBook(bookId));
    }

}













